package com.haoan.index.service.impl;


import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoan.index.common.enums.ValiFlag;

import com.haoan.index.mapper.CarouselMapper;
import com.haoan.index.domain.Carousel;
import com.haoan.index.service.CarouselService;

/**
 * 轮播图Service业务层处理
 * 
 * @author autoGen
 * @date 2025-01-03
 */
@Service
public class CarouselServiceImpl extends ServiceImpl<CarouselMapper,Carousel> implements CarouselService
{
    /**
     * 查询轮播图
     * 
     * @param id 轮播图主键
     * @return 轮播图
     */
    @Override
    public Carousel selectCarouselById(Long id)
    {
        return baseMapper.selectById(id);
    }

    /**
     * 查询轮播图列表
     * 
     * @param carousel 轮播图
     * @return 轮播图
     */
    @Override
    public List<Carousel> selectCarouselList(Carousel carousel)
    {
        LambdaQueryWrapper<Carousel> queryWrapper = new LambdaQueryWrapper<>();
        //todo 添加查询条件
        queryWrapper.eq(carousel.getId() != null, Carousel::getId, carousel.getId());
        queryWrapper.eq(carousel.getCarousel() != null, Carousel::getCarousel, carousel.getCarousel());
        queryWrapper.eq(carousel.getType() != null, Carousel::getType, carousel.getType());
        queryWrapper.eq(carousel.getStatus() != null, Carousel::getStatus, carousel.getStatus());
        queryWrapper.eq(carousel.getCreateTime() != null, Carousel::getCreateTime, carousel.getCreateTime());
        queryWrapper.eq(carousel.getCreateBy() != null, Carousel::getCreateBy, carousel.getCreateBy());
        queryWrapper.eq(carousel.getUpdateTime() != null, Carousel::getUpdateTime, carousel.getUpdateTime());
        queryWrapper.eq(carousel.getUpdateBy() != null, Carousel::getUpdateBy, carousel.getUpdateBy());
        queryWrapper.eq(Carousel::getValiFlag,ValiFlag.VALID );
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 新增轮播图
     * 
     * @param carousel 轮播图
     * @return 结果
     */
    @Transactional
    @Override
    public int insertCarousel(Carousel carousel)
    {
        return baseMapper.insert(carousel);
    }

    /**
     * 修改轮播图
     * 
     * @param carousel 轮播图
     * @return 结果
     */
    @Transactional
    @Override
    public int updateCarousel(Carousel carousel)
    {
        return baseMapper.updateById(carousel);
    }

    /**
     * 批量删除轮播图
     * 
     * @param ids 需要删除的轮播图主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteCarouselByIds(Long [] ids)
    {
        Carousel carousel = new Carousel();
        carousel.setValiFlag(ValiFlag.INVALID);
        LambdaQueryWrapper<Carousel> updQw = new LambdaQueryWrapper<>();
        updQw.in(Carousel::getId, ids);
        return baseMapper.update(carousel, updQw);
    }

    /**
     * 删除轮播图信息
     * 
     * @param id 轮播图主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteById(Long id)
    {
        Carousel carousel = getById(id);
        carousel.setValiFlag(ValiFlag.INVALID);
        return baseMapper.updateById(carousel);
    }
}
